#include "TextureCube.h"

namespace egg{

    TextureCube::TextureCube(
    const Image2D& _posX,const Image2D& _negX, 
    const Image2D& _posY,const Image2D& _negY, 
    const Image2D& _posZ,const Image2D& _negZ):
    Texture(GL_TEXTURE_CUBE_MAP){
        glGenTextures(1,&mID);
        glBindTexture(mType,mID);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X,_posX);
        setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,_negX);
        setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,_posY);
        setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,_negY);
        setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,_posZ);
        setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,_negZ);
        glBindTexture(mType,0);
        GraphicDevice_CatchError;
    }

    void TextureCube::setImage(GLuint _target,const Image2D& _img){
        glTexImage2D(
            _target, 0, GL_RGBA,
            _img.mWidth, _img.mHeight,
            0, GL_RGBA, GL_UNSIGNED_BYTE, _img.mPixels);
    }

}